package com.ttx.pattern.example.observer.after;

import java.util.ArrayList;
import java.util.List;

/**
 * 可订阅的杂志
 * 
 * @author TimFruit
 * @date 2019/5/21 13:57
 */

public class Magazine implements Subject {
    
    private List<Observer> observers=new ArrayList<>(8);
    
    private String updateContent; //更新的内容
    
    @Override 
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override 
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override 
    public void notifyObservers() {
        for(Observer observer: observers){
            observer.update(updateContent);
        }
    }
    
    
    
    // ---------------------------- 
    public void updateContent(String content){
        this.updateContent=content;
        // 通知观察者 
        this.notifyObservers();
    }
    
    
    
}
